/**
 * <p>
 * 版权所有：中企动力
 * </p>
 * <p>
 * 未经本公司许可，不得以任何方式复制或使用本程序任何部分
 * </p>
 */
package com.ce.pms.report.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ce.pms.report.queryvo.DosageListQueryVo;
import com.ce.pms.report.vo.BaseReportVo;
import com.ce.pms.report.vo.DosageCollectVo;
import com.ce.pms.report.vo.DosageListVo;
import com.ce.report.entity.CEReportDataSet;
import com.ce.report.exception.CEReportException;
import com.ce.report.service.ICEReportDataSetService;
import com.ce.report.vo.ReportsQueryBaseVo;
import com.ce.util.DateUtil;

/**
 * 用量明细表
 * 
 * @author <a href="mailto:i0o@live.cn">黄腾飞</a>
 * @Created 2008-11-13
 */

public class DosageListService extends BaseReportService implements
		ICEReportDataSetService {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ce.pms.report.service.BaseReportService#converToReportVoList(java
	 * .util.List)
	 */
	@Override
	protected List<BaseReportVo> converToReportVoList(List<Object[]> dataList) {
		List<BaseReportVo> list = new ArrayList<BaseReportVo>();

		for (Object[] dataTmp : dataList) {
			DosageListVo dasageCollet = new DosageListVo();

			dasageCollet.setHouseNumber((String) dataTmp[0]);// 房号
			dasageCollet.setUserName((String) dataTmp[1]);// 客户
			dasageCollet.setLastIndication(setValue(dataTmp[2]));
			dasageCollet.setIndication(setValue(dataTmp[3]));
			dasageCollet.setDosage(setValue(dataTmp[4]));// 计费用量
			dasageCollet.setChargeCount(setValue(dataTmp[5]));// 费用总计

			list.add(dasageCollet);
		}

		return list;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ce.report.service.ICEReportDataSetService#getReportDataSet(com.ce
	 * .report.vo.ReportsQueryBaseVo)
	 */
	public CEReportDataSet getReportDataSet(
			ReportsQueryBaseVo reportsQueryBaseVo) throws CEReportException {
		DosageListQueryVo queryVo = (DosageListQueryVo) reportsQueryBaseVo;

		// 获取请求参数
		String doeageType = queryVo.getDosageType();
		String monthDate = DateUtil.convertDateToStr(queryVo.getMonthDate(),
				"yyyyMM");
		String precinct = queryVo.getPrecinct();
		String building = queryVo.getBuilding();

		if (building == null) {
			building = "%%";
		}

		List<Object[]> data = reportDao.getDataList("DosageList", doeageType,
				monthDate,precinct,building);

		Map<String, Object> queryPram = getHeadInfo(queryVo);

		List<BaseReportVo> list = converToReportVoList(data);
		if (list.size() == 0)
			list.add(new DosageCollectVo());
		return new CEReportDataSet(list, queryPram);
	}

	/**
	 * @param queryVO
	 * @return
	 * @author <a href="mailto:i0o@live.cn">黄腾飞</a>
	 * @created 2008-11-28
	 */
	private Map<String, Object> getHeadInfo(DosageListQueryVo queryVo) {
		String title = DateUtil.convertDateToStr(queryVo.getMonthDate(),
				"yyyy年MM月份");
		String reportHeadStr = null;

		Map<String, Object> headerMap = new HashMap<String, Object>();
		headerMap.put("title", title);
		headerMap.put("reportHeadStr", reportHeadStr);
		return headerMap;
	}

}
